//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.view.components
{
	import flash.display.DisplayObject;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.controls.ProgressBar;
	import mx.controls.ProgressBarMode;
	import mx.core.Application;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;

	public class Hourglass extends UIComponent
	{
		/////////////////////////////////////////////////////////////////////////////////
		// Private Variables
		
		private var timer:Timer;
		
		//////////////////////////////////////////////////////////////////////////////
		//Constructor
		public function Hourglass()
		{
			super();
			var progressBar:ProgressBar = new ProgressBar();
			progressBar.indeterminate = true;
			progressBar.width = 100;
			
			timer = new Timer(5000);
			timer.addEventListener(TimerEvent.TIMER, onTimer_handler);
			timer.start();
			this.addChild(progressBar);
			PopUpManager.addPopUp(this, Application.application as DisplayObject, true);
			PopUpManager.centerPopUp(this);
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		// methods
		
		public function Cancel():void {
			PopUpManager.removePopUp(this);
		}
		
		/////////////////////////////////////////////////////////////////////////////////
		// events
		
		private function onTimer_handler(e:TimerEvent):void
		{
			this.Cancel();
			timer.stop();
		}
	}
}